package com.example.activity.domain.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


@Data
@AllArgsConstructor
@NoArgsConstructor
@SuppressWarnings("unused")
public class ResponseResult<T> {
    private int code;
    private String msg;
    private T data;

    /**
     * 成功请求
     * @param data 需要封装的对象
     * @param <T> 对象类型
     * @return ResponseResult对象
     */
    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(HttpCodeEnum.OK.getCode(), HttpCodeEnum.OK.getMessage(), data);
    }
    /**
     * 成功请求(无数据)
     * @return ResponseResult对象
     */
    public static  ResponseResult<?> success() {
        return new ResponseResult<>(HttpCodeEnum.OK.getCode(), HttpCodeEnum.OK.getMessage(), null);
    }

    /**
     * 失败请求
     * @return ResponseResult对象
     */
    public static ResponseResult<?> fail() {
        return new ResponseResult<>(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMessage(), null);
    }

    /**
     * 自定义构造响应对象
     * @param msg httpCodeEnum
     * @param data 构造数据
     * @param <T> 数据类型
     * @return ResponseResult
     */
    public static <T> ResponseResult<T> build(HttpCodeEnum msg, T data) {
        return new ResponseResult<>(msg.getCode(), msg.getMessage(), data);
    }
}